<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="search" />

    <MyCase :list="renderList" @detail="detail" />
    <MyPros @close="close" v-show="flag" :list="renderList" />
  </div>
</template>

<script>
import MyCase from '@/components/MyCase.vue'
import MyPros from '@/components/MyPros.vue'
export default {
  components: {
    MyCase,
    MyPros,
  },

  data() {
    return {
      search: '',
      flag: false,
      renderList: '',
      list: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        },
      ],
    }
  },
  methods: {
    detail(id) {
      this.flag = true
      this.renderList = this.list.filter((item) => item.id === id)
    },
    close() {
      this.flag = false
    },
  },
  computed: {
    renderList() {
      return this.list.filter((item) => {
        return (
          item.date.includes(this.searchKeyWords) ||
          item.doctor.includes(this.searchKeyWords) ||
          item.diagnosis.includes(this.searchKeyWords) ||
          item.prescription.includes(this.searchKeyWords)
        )
      })
    },
  },
}
</script>

<style scoped></style>
